"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.RefForward = void 0;

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var React = _interopRequireWildcard(require("react"));

var _utils = require("./utils");

var RefForward = /*#__PURE__*/function (_React$Component) {
  (0, _inheritsLoose2.default)(RefForward, _React$Component);

  function RefForward() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.currentNode = null;

    _this.handleRefOverride = function (node) {
      var _this$props = _this.props,
          children = _this$props.children,
          innerRef = _this$props.innerRef;
      (0, _utils.handleRef)(children.ref, node);
      (0, _utils.handleRef)(innerRef, node);
      _this.currentNode = node;
    };

    return _this;
  }

  var _proto = RefForward.prototype;

  _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
    if (prevProps.innerRef !== this.props.innerRef) {
      (0, _utils.handleRef)(this.props.innerRef, this.currentNode);
    }
  };

  _proto.componentWillUnmount = function componentWillUnmount() {
    delete this.currentNode;
  };

  _proto.render = function render() {
    var children = this.props.children;
    return /*#__PURE__*/React.cloneElement(children, {
      ref: this.handleRefOverride
    });
  };

  return RefForward;
}(React.Component);

exports.RefForward = RefForward;
//# sourceMappingURL=RefForward.js.map
